<?php  // Продукт в каталоге

class product extends Load_use
{
	function getBlock()
	{
		$users = isset( $GLOBALS['users'] ) ? $GLOBALS['users'] : array();  // Менеджеры
		$admin = in_array( $this->user->id, $users ) ? true : false;
		
		
		$product = $this->getParam( 'product', 0 );
		
		//подарка данные
		$present_name = $this->getParam('present_name', '');
		$present_url = $this->getParam('present_url', '');

		if( $present_name != '' && $present_url != '' ) {
			$present_html = '
			<div class="present">
				<div class="present_inner">
					<span class="present_box"></span>
					<div class="present_text">
						<div class="present_text_inner">
							При покупке <a target="_blank" href="'.$present_url.'">'.$present_name.'</a> бесплатно, в подарок!
							<span class="present_text_triangle"></span>
						</div>
					</div>
				</div>
			</div>';
		}
		else
			$present_html = '';
			
		//новогодние бонусы
		$product_credits = $this->getParam('product_credit', '');
		
		if( $product_credits ) {
			$product_credits_html = '<a href="/bonusnaya-akciya" title="Новогодняя акция" class="ny_product_bottom">'.$product_credits.'</a>';
		}
		else
			$product_credits_html = '';
			
		$status_html = $this->getStatus( $product );
		$button = $this->getButtonInBasket( $product );
		$stickers = $this->getStickers( $product );
		$installation = $this->getInstallation( $product );
		
		
		$action_html = '';
		$product_codes_for_action_1 = array( 800127 ,800128 ,800129 ,800131 ,2001326 ,2001945 ,2001946 ,2003693 ,2003694 ,2003695 ,2003703 ,2003704 ,2003705 ,2003706 );
		if( in_array( $product->product_code, $product_codes_for_action_1 ) && in_array( $product->pp, array( 1, 3, 4, 5 ) ) )
			$action_html = '
				<a href="/akcii/akciya-na-tehniku-asko" class="status promotion-goods" title="Месяц подарков!" target="_blank">
					<span class="status__inner"><span>Акция</span></span>
				</a>';

				
		$product_codes_for_action_2 = array( /*5003927, 5003928, 5003929, 5003963, 5005380, 1000390*/ );
		if( in_array( $product->product_code, $product_codes_for_action_2 ) && in_array( $product->pp, array( 1, 3, 4, 5 ) ) )
			$action_html = '
				<a href="/akcii/rayskiy-klimat" class="status promotion-goods" title="Райский климат!" target="_blank">
					<span class="status__inner"><span>Акция</span></span>
				</a>';
	
		return '
			<li>
				<div class="one-product anchor_one_product">
					<input type="hidden" class="product_code" value="'.$product->product_code.'"/>'
					.(
						( $product_credits_html == '' ) ? 
							$stickers.'
							<a href="/'.$product->url.'" class="status-list">
								'.$status_html.'
								'.$action_html.'
							</a>'
							.$installation.
							(
								( $product->sale == 1 ) ? 
									'<div class="sale"><span>Распродажа</span></div>' 
									: '' 
							)
						: ''
					).
					'<div class="global-photo">
						<div class="ny_product_page_top">&nbsp;</div>
						<a href="/'.$product->url.'">
							<img src="'.getImageSrcNew( $product->product_code , $size = 'b' ).'" alt="'.$product->prefix.' '.( $product->brand != 'noname' ? $product->brand : '').' '.$product->name.'" />
						</a>
						'.(( $product_credits_html == '' ) ? $present_html : $product_credits_html).'
					</div>
					<div class="title">
						<a href="/'.$product->url.'">
							'.$product->prefix.' '.( $product->brand != 'noname' ? $product->brand : '').' <strong>'.( $admin ? ruWrap( $product->name ) : $product->name ).'</strong>
						</a>
					</div>
					<div class="one-product__middle-list">
						<div>
							<span class="one-product__price">'.getPriceFormat( $product->price_retail ).' руб.</span>
						</div>
						<div>
							<dl class="one-product__rating">
								<dt>Рейтинг:</dt>
								<dd>5.0</dd>
							</dl>
						</div>
					</div>
					<div class="one-product__bottom-list">
						<div>
							'.$button.'
						</div>
						<div>
							<a href="#compare" class="one-product__compare button_compare">Сравнить</a>
						</div>
					</div>
				</div>
			</li>';
	}

	function getInstallation( $product )
	{
		global $view;
		if( strlen( $product->price_inst ) && $product->price_inst == 0 &&
			isset($view->parents_arr[2]) && $view->parents_arr[2]->url == 'split-sistemy' )
			return '<a href="/'.$product->url.'" class="one-product__installation">
						<span>Установка бесплатно</span>
					</a>';
		return '';
	}
	
	function getStatus( $product )
	{
		$status = '';
		switch ( $product->pp )
		{
			case 0:
				$status = '<span class="status not-available">
								<span class="status__inner"><span>Нет&nbsp;в&nbsp;наличии</span></span>	
							</span>';
				break;
			case 1:
				$status = '<span class="status available"><span class="status__inner"><span>Есть&nbsp;в&nbsp;наличии</span></span></span>';
				break;
			case 3:
			case 4:
			case 5:
				$status = '<span class="status pre-order"><span class="status__inner"><span>Под&nbsp;заказ</span></span></span>';
				break;
		}
		return $status;
	}
	
	function getButtonInBasket( $product )
	{
		$button = '';
		switch ( $product->pp )
		{
			case 0:
				$button = '<button class="global-button gray-bg disabled" disabled="disabled">
									<span class="global-button__inner icon-basket">В корзину</span>
								</button>';
				break;
			default:
				$button = '<button class="global-button button_add_to_cart">
									<span class="global-button__inner icon-basket">В корзину</span>
								</button>';
		}
		return $button;
	}
	
	function getStickers( $product )
	{
		$stickers = '';
		if( $product->new == 1 && $product->hit == 1 )
		{
			$stickers = '<div class="novelty-sales-hit"><span>Хит продаж и новинка</span></div>';
		}
		else
		{
			if( $product->new == 1 )
				$stickers = '<div class="novelty"><span>Новинка</span></div>';
			if( $product->hit == 1 )
				$stickers = '<div class="sales-hit"><span>Хит продаж</span></div>';
		}
		return $stickers;
	}

}